package com.cloudOffice.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cloudOffice.model.process.ProcessType;
import com.cloudOffice.result.Result;
import com.cloudOffice.service.OaProcessTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 审批类型
 */
@Slf4j
@Tag(name = "审批类型")
@RestController("OaProcessTypeController")
@RequestMapping("/admin/process/processType")
public class OaProcessTypeController {
	
	@Resource
	private OaProcessTypeService processTypeService;
	
	//查询所有审批分类
	@GetMapping("findAll")
	public Result<List<ProcessType>> findAll() {
		log.info("查询所有审批分类");
		return Result.success(processTypeService.list());
	}
	
	@Operation(summary = "获取分页列表")
	@GetMapping("{page}/{limit}")
	public Result<IPage<ProcessType>> index(@PathVariable Long page,
	                                        @PathVariable Long limit) {
		log.info("获取分页列表：page: {}, limit: {}", page, limit);
		Page<ProcessType> pageParam = new Page<>(page, limit);
		return Result.success(processTypeService.page(pageParam));
	}
	
	// 根据id获取审批分类
	@Operation(summary = "根据id获取审批分类")
	@GetMapping("get/{id}")
	public Result<ProcessType> get(@PathVariable Long id) {
		log.info("根据id获取审批分类：id: {}", id);
		return Result.success(processTypeService.getById(id));
	}
	
	//  新增审批分类
	@Operation(summary = "新增审批分类")
	@PostMapping("save")
	public Result<?> save(@RequestBody ProcessType processType) {
		log.info("新增审批分类：processType: {}", processType);
		processTypeService.save(processType);
		return Result.success();
	}
	
	//  修改审批分类
	@Operation(summary = "修改审批分类")
	@PutMapping("update")
	public Result<?> updateById(@RequestBody ProcessType processType) {
		log.info("修改审批分类：processType: {}", processType);
		processTypeService.updateById(processType);
		return Result.success();
	}
	
	//  删除审批分类
	@Operation(summary = "删除审批分类")
	@DeleteMapping("remove/{id}")
	public Result<?> remove(@PathVariable Long id) {
		log.info("删除审批分类：id: {}", id);
		processTypeService.removeById(id);
		return Result.success();
	}
}

